﻿Imports System.Data.OleDb


Public Class AddHotel
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myGuid As New System.Guid
        Dim newFileName = myGuid.ToString() + ".jpg"

        If f_picture.HasFile Then
            Dim picLocationOnServerHardDisk = Request.MapPath("pictures") & "/" & newFileName
            f_picture.SaveAs(picLocationOnServerHardDisk)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into Hotels(Hotel_Name,Stars,Location,Description,ContactDetails,Picture,HotelUrl) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_hotelName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_location.Text)
        cmd.Parameters.AddWithValue("@f3", rbl_stars.SelectedValue)
        cmd.Parameters.AddWithValue("@f4", tb_description.Text)
        cmd.Parameters.AddWithValue("@f5", tb_contactdetails.Text)
        cmd.Parameters.AddWithValue("@f6", "pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f7", tb_HotelUrl.Text)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub
End Class